package com.itheima.controller;

import com.itheima.pojo.R;
import com.itheima.pojo.Student;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/findByClassId")
    public R findByClassId(){
       List<Student> students= userService.findByClassId();
        R r = new R();
        r.setCode(0);
        r.setErrorMessage("操作成功");
        r.setData(students);
       return r;
    }

    @PostMapping("addIntegral")
    public R addIntegral(@RequestBody Student student) {
        int count = userService.addIntegral(student);
        if (count > 0) {
            R r = new R();
            r.setCode(0);
            r.setErrorMessage("操作成功");
            r.setData("添加积分成功");
            return r;
        }
        R r = new R();
        r.setCode(1);
        r.setErrorMessage("操作失败");
        return r;
    }
}
